
'''
 具名元组： namedtuple

 具名元组在存储csv或者sqlite3返回数据的时候特别有用
'''


from collections import namedtuple

P = namedtuple('point',['x', 'y'])

p = P(1,3)
print(p)
print(p[0])
print(p.x, p.y)

help(P._make)

# _make
print(P._make([1,2]))

# _asdict  OrderedDict
print(p._asdict())

# _relpace
p._replace(x=10)

print(namedtuple.__doc__)

# 扑克牌
class Cards():
    f = ['y', 'h', 'he', 'f']
    n = [str(i) for i in range(2, 11)] + 'JQKA'.split()
    c = namedtuple('card', 'number     color')
    def __init__(self):
        self._cards = [self.c._make((i,flower)) for i in self.n for flower in self.f]
    def __getitem__(self, item):
        return self._cards[item]

c = Cards()
print(c[10])
print(c[0])